import requests  # 导入requests模块
import csv  # 导入csv模块
import json

uid=[2123631024,4162287]

def spider(uid):
    url = 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?visitor_uid=0&host_uid='+str(uid)+'&offset_dynamic_id=0&need_top=1&platform=web'
    r = requests.get(url).json()
    for card in r['data']['cards']:
        #content_tmp = r['data']['cards'][0]['card']
        content_tmp = card['card']
        content_json = json.loads(content_tmp)
        pictures = []
        if('item' in content_json):
            if('content' in content_json['item']):
                content = content_json['item']['content']
            elif('description' in content_json['item']):
                content = content_json['item']['description']
                pictures = content_json['item']['pictures']
            else:
                content = 'up发布了甚么？？？'
        else:
            content = content_json['dynamic']
        if(content==''):
            content = 'up发了个无文字动态，应该是发新视频了>w<'
        print(content)
        if(len(pictures)!=0):
            print(pictures)
        print('-------')
print('-------')
spider(uid[0])